package com.atguigu.tingshu.common.util;

/**
 * 线程工具类--存储用户id和用户名
 * @author sun
 */
public class AuthContextHolder {

    private static final ThreadLocal<Long> USER_ID = new ThreadLocal<>();
    private static final ThreadLocal<String> USERNAME = new ThreadLocal<>();

    public static void setUserId(Long userId) {
        USER_ID.set(userId);
    }

    public static Long getUserId() {
        return USER_ID.get();
    }

    public static void removeUserId() {
        USER_ID.remove();
    }

    public static void setUsername(String username) {
        USERNAME.set(username);
    }

    public static String getUsername() {
        return USERNAME.get();
    }

    public static void removeUsername() {
        USERNAME.remove();
    }

    public static void clear() {
        removeUserId();
        removeUsername();
    }

}
